﻿using SafoverWpfFw;
using System.Windows;
using Safover.LidarCollector.Core;
using Safover.LidarCollector.Managers;
using Safover.LidarCollector.ViewModel;

namespace Safover.LidarCollector.View
{
    /// <summary>
    /// Interaction logic for CollectionPage.xaml
    /// </summary>
    public partial class CollectionPage : BasePage<CollectionPageViewModel>
    {
        private CameraWindow CameraWindow { get; set; }

        public CollectionPage() : this(null)
        { }

        public CollectionPage(CollectionPageViewModel specificViewModel = null) : base(specificViewModel)
        {
            InitializeComponent();

            CameraWindow = new CameraWindow()
            {
                Owner = Application.Current.MainWindow,
            };

            Loaded += OnLoaded;

            Unloaded += OnUnloaded;
        }

        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            DeviceManager.DeviceFactoryInstance.AcquisitionCard.Unsubscribe(DataContext as ILidarDataListenner);
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            DeviceManager.DeviceFactoryInstance.AcquisitionCard.Subscribe(DataContext as ILidarDataListenner);
        }

        private void OpenCameraWindow(object sender, RoutedEventArgs e)
        {
            _ = CameraWindow.ShowDialog();
        }
    }
}
